<?php

declare (strict_types=1);

namespace app\controller\admin;

use think\App;
use think\facade\View;
use think\facade\Cookie;
use app\middleware\AdminAuth;

abstract class Common
{
    protected $request;
    public $cyConfig;
    public $lang;
    protected $middleware = [AdminAuth::class];

    public function __construct(App $app)
    {
        $this->request = $app->request;
        $this->initialize();
    }

    public function initialize()
    {

        $lang = $this->request->param('lang');
        if ($lang) {
            cookie(config('lang.cookie_var'), $lang);
        } else {
            $lang = cookie(config('lang.cookie_var'));
            if ($lang == '') {
                $lang = config('lang.default_lang');
            }
        }
        $this->lang = $lang;
        View::assign('lang', $lang);

        #获取配置
        $this->cyConfig = config('cy');
        View::assign('cyConfig', $this->cyConfig);
    }
}
